#!/usr/local/bin/python3.6
# coding:utf-8
# @Time    : 2019/11/20 16:58
# @Author  : ZhangBing
# @Email   : 18829272841@163.com
# @File    : products.py
# @Software: PyCharm
import pika
import sys

# 创建链接
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
# 创建通道
channel = connection.channel()
# 创建队列

# Linux端查看通道 rabbitmqctl list_queues
# 产生消息
severity = sys.argv[1] if len(sys.argv) > 1 else 'info'
message = ' '.join(sys.argv[2:]) or "hello world!"
# 发送消息
channel.exchange_declare(exchange='direct_logs',  # 定义消息名称
                         exchange_type='direct')  # 定义消息类型,此处是直通路由模式

channel.basic_publish(exchange='direct_logs',  # 此处引用消息
                      routing_key='',  # 指定通道
                      body=message,
                      )
print(" {}  {} Sent 'Hello World!'".format(severity, message))
connection.close()

if __name__ == "__main__":
    pass
